package cn.com.open.opensaas.answerservice.service.impl;

import cn.com.open.opensaas.answerservice.common.QuestionConstant;
import cn.com.open.opensaas.answerservice.mapper.QuestionContentMapper;
import cn.com.open.opensaas.answerservice.model.question.QuestionContent;
import cn.com.open.opensaas.answerservice.model.question.QuestionContentJsonModel;
import cn.com.open.opensaas.answerservice.service.QuestionContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class QuestionContentServiceImpl implements QuestionContentService {


    @Autowired
    private QuestionContentMapper questionContentMapper;

    /**
     * 根据Ids批量获取QuestionContent
     * @param questionIds
     * @return
     */
    @Override
    public List<QuestionContent> findDBQuestionByIds(List questionIds) {
        return questionContentMapper.findDBQuestionByIds(questionIds);
    }

    /**
     * 根据学生答案批量获取数据库中对应数据
     * @param answerList
     * @return
     */
    @Override
    public List<QuestionContent> batchFindDbQuestion(List<QuestionContentJsonModel> answerList) {
        //用来存储questionList中Id集合，用于批量获取数据库中对应数据
        List questionIds = new ArrayList();
        for (QuestionContentJsonModel question : answerList) {
            questionIds.add(question.getI1());
        }
        if (questionIds.isEmpty()) {
            questionIds.add("");
        }
        //调用数据库查询(key-questionId value-contentJson)
        return findDBQuestionByIds(questionIds);
    }
}
